package com.ZLHW.base.HTable;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.io.Serializable;
import java.util.Date;
@MappedSuperclass
public abstract class BasicModel implements Serializable{
    @Temporal(TemporalType.TIMESTAMP)
    private Date createDate;               //创建日期

    @Temporal(TemporalType.TIMESTAMP)
    private Date updateDate;               //更新日期

    /**
     * Getter for property 'updateDate'.
     *
     * @return Value for property 'updateDate'.
     */
    public Date getUpdateDate() {
        return updateDate;
    }

    /**
     * Setter for property 'updateDate'.
     *
     * @param updateDate Value to set for property 'updateDate'.
     */
    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    /**
     * 获取主键值
     */
    public abstract Serializable primary();

    /**
     * 获取主键名称
     */
    public abstract String primaryColumn();

    public String extendTableName() {
        return "BaseModel";
    }

    /**
     * 判断两个对象是否相等
     * @param tb
     * @return
     */
    public boolean equalWithByPrimary(BasicModel tb) {
        if (tb == null)
            return false;
		if(tb.getClass()==this.getClass()&&this.primary().equals(tb.primary())){
			return true;
		}else{
			return false;
		}
	}


    /**
     * Getter for property 'createDate'.
     *
     * @return Value for property 'createDate'.
     */
    public Date getCreateDate() {
        return createDate;
    }

    /**
     * Setter for property 'createDate'.
     *
     * @param createDate Value to set for property 'createDate'.
     */
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String toString(){
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
